#include"process.h"
#include<string.h>
#include<unistd.h>
#define SIZE 101
#define STYLE '.'
void FlushProcess(double total,double cur)
{
  //当前的下载总量可能超过了总量
  if(cur > total)
  cur = total;
  //计算当前百分比进度
  double rate = cur / total * 100;
  int cnt =(int) rate;//保留整数
  char processbuffer[SIZE];
  memset(processbuffer,'\0',sizeof(processbuffer));
  const char* state = "|/-\\";
  int len = strlen(state);
  int i = 0;
  for(;i <= cnt;i++)
{
  processbuffer[i] = STYLE;
}
//打印进度条
//printf("[%-100s][%.1lf%%][%c]\r",processbuffer,rate,state[cnt%len]);
//printf("\e[31m[%-100s][%.1lf][%c]\e[0m\r",processbuffer,rate,state[cnt%len]); 
//printf ("\033[40;37m[%-100s][%.1lf][%c]\033[0m\r",processbuffer,rate,state[cnt%len]);
//printf( "\033[47;34m[%-100s][%.1lf][%c]\033[0m\r",processbuffer,rate,state[cnt%len]);
//printf( "\033[40;31m[%-100s][%.1lf][%c]\033[0m\r",processbuffer,rate,state[cnt%len]);
//加粗效果（部分终端显示更清晰）
printf("\033[47;1;30m[%-100s][%.1lf][%c]\033[0m\r",processbuffer,rate,state[cnt%len]);
// 真彩色模式（支持RGB的终端）
//printf( "\033[48;2;0;0;0m\033[38;2;255;255;255m[%-100s][%.1lf%%][%c]\033[0m\r",processbuffer,rate,state[cnt%len]);
fflush(stdout);
if(cur >=total)
printf("\n");
}

//verson1 展示原理
//`void Process()
//{
//char processbuffer[SIZE];
//const char* state = "|/-\\";
//int len = strlen(state);
//memset(processbuffer,'\0',sizeof(processbuffer));
//int cnt = 0;
//while(cnt<=100)
//{
//printf("[%-100s][%d%%][%c]\r",processbuffer,cnt,state[cnt%len]);
//fflush(stdout);
//processbuffer[cnt++] = STYLE;
//usleep(30000);
//}
//printf("\n");
////printf("测试\n");
//}

